package com.dangwen.proto.service;
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttCallback;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.springframework.stereotype.Component;

@Component
public class MqttSubscriberListener implements MqttCallback {
    @Override
    public void connectionLost(Throwable throwable) {
        System.out.println("连接丢失：" + throwable.getMessage());
    }

    @Override
    public void messageArrived(String topic, MqttMessage message) {
        // 处理接收到的消息
        System.out.println("接收到消息: " + new String(message.getPayload()));
        System.out.println("主题: " + topic);
    }

    @Override
    public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
        System.out.println("消息发送完成：" + iMqttDeliveryToken.isComplete());
    }
}
